Skip to content

feat(autonatv2): expose AllowPrivateAddrs via an Option#3513

Open
gmelodie wants to merge 1 commit into
libp2p:masterfrom
gmelodie:master
Open

feat(autonatv2): expose AllowPrivateAddrs via an Option#3513
gmelodie wants to merge 1 commit into
libp2p:masterfrom
gmelodie:master

Conversation

@gmelodie
Copy link
Copy Markdown

@gmelodie gmelodie commented May 28, 2026

Summary

Expose AutoNATv2's allowPrivateAddrs setting through the top-level libp2p
package so callers can opt in without patching the library.

Changes

  • p2p/protocol/autonatv2

    • Rename the private allowPrivateAddrs field/option to the exported
      AllowPrivateAddrs (commit e3a1d72d).
  • config, options.go

    • Add Config.AutoNATv2AllowPrivateAddrs.
    • Add a new libp2p.AutoNATv2AllowPrivateAddrs() option.
    • When used alongside EnableAutoNATv2(), the fx provider passes
      autonatv2.AllowPrivateAddrs to autonatv2.New
      (commit b85ffade).
  • libp2p_test.go

    • Add a smoke test verifying that:

      New(
          EnableAutoNATv2(),
          AutoNATv2AllowPrivateAddrs(),
      )

      successfully builds a host.

Motivation

nim-libp2p's AutoNATv2 interop tests currently maintain a patch against
go-libp2p to disable private-address filtering:

  • disable-filtering-of-private-ip-addresses.patch
    (interop/autonatv2/go-peer/...)

The setting already exists internally; this change simply exposes it through the
public API so the patch can be removed (see nim-libp2p#1699).

Notes

@gmelodie gmelodie marked this pull request as ready for review May 28, 2026 12:04
// autoNATSettings is used to configure AutoNAT
type autoNATSettings struct {
allowPrivateAddrs bool
AllowPrivateAddrs bool
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this field (and other similar fields across this diff) need to be public?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On nim-libp2p we have an integration test between nim-libp2p and go-libp2p for autonat, since that is not yet present in https://github.com/libp2p/unified-testing. For that we need to allow private addresses on go-libp2p (just like you do in your tests), but there's no way to do that as a user currently. What we've been doing is cloning go-libp2p and applying an ugly patch instead. This makes the option public so we no longer have to do that there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do you need the field of the autoNATSettings struct to be public? Remember in Go, when you capitalize a field you make it public to users outside the package it is defined in.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two scripts that instanciate peers: one in go that imports go-libp2p and another one in nim that imports nim-libp2p, they instanciate autonat-capable peers and communicate. For that test, the go script (a "user outside the package", if you will) needs to be able to set autonat settings, specifically the one that allows private ip addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants